package com.pactera.integral.controller;

import java.util.HashMap;

import javax.annotation.Resource;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.pactera.integral.common.web.GenericController;
import com.pactera.integral.common.web.Response;
import com.pactera.integral.entity.PerformanceScore;
import com.pactera.integral.service.PerformanceScoreService;

@CrossOrigin
@Controller
@RequestMapping("adm/performanceScore")
public class PerformanceScoreController extends GenericController{

	@Resource
	private PerformanceScoreService performanceScoreService;
	
	/**
	 * 积分项列表
	 * @param param
	 * @param pageable
	 * @return Response
	 */
	@PostMapping("/page")
	@ResponseBody  
    public Response getPerformanceScorePage(@RequestBody HashMap<String,Object> param, Pageable pageable) {
    	Page<PerformanceScore> page = performanceScoreService.pagePerformanceScore(param, pageable);
		
    	return this.normal(page); 
	}
    
	/**
	 * 添加或修改积分项
	 * @param performanceScore
	 * @return Response
	 */
	@RequestMapping(value = "/save",method = RequestMethod.POST)
	@ResponseBody
    public Response save(@RequestBody PerformanceScore performanceScore) {
		try {
			performanceScoreService.save(performanceScore);
			
			return this.normal();
		} catch (Exception ex) {
			return this.error(ex.getMessage());
		} 
    }
	
	/**
	 * 积分项明细
	 * @param id
	 * @return Response
	 */
	@RequestMapping(value = "/detail",method = RequestMethod.GET)
	@ResponseBody
    public Response getAdditionalScore(@RequestParam(value = "id", required = false) String id) {
       
		return this.normal(performanceScoreService.getperformanceScore(id)); 
    }
	
	/**
	 * 删除积分项
	 * @param id
	 * @return Response
	 */
	@RequestMapping(value = "/delete",method = RequestMethod.GET)
	@ResponseBody
    public Response delete(@RequestParam(value = "id", required = false) String id) {
       
		return this.normal(performanceScoreService.delete(id)); 
    }

}
